 <?php
 include "class/komentar.php";
 
 if (ISSET($_POST["tambah"]) && $_POST['nama']!="" && $_POST['email']!="" && $_POST['komentar']!="" && $_POST['id_oleh2']!="" ){
	$komentar_dao = new Komentar_Dao();
	$komentar=new Komentar();
	$komentar->nama = $_POST['nama'];
	$komentar->email = $_POST['email'];
	$komentar->komentar = $_POST['komentar'];
	$komentar->date = $_POST['date'];
	$komentar->id_oleh2 = $_POST['id_oleh2'];
	$komentar_dao->add($komentar);
	if ($komentar) {
		header ("location:index.php?menu=view_produkdetil&id_oleh2=$komentar->id_oleh2");
	}
}
?>
<br>
  <form method="post" action="view_produkdetil.php">
	<input type="hidden" name="tambah" value="form_tambah">
	<input type="hidden" name="date" value=<?php echo date("Y-m-d"); ?>>
	<input type="hidden" name="id_oleh2" value=<?php echo $produk->id_oleh2; ?>>
  <table width="500" align="center">
  	<tr>
  	  <td colspan=2></td><td align=left><font color="#000000" size="2" face="tahoma">Silahkan Isi Komentar Anda<br><br></font></td>
  	</tr>
    <tr valign="top"> 
      <td width="170"><font color="#000000" size="2" face="tahoma">Nama</font></td>
      <td width="10"><font color="#000000" size="2" face="tahoma">:</font></td>
      <td width="320"><input name='nama' type='text' id="nama" size="30"></td>
    </tr>
    <tr valign="top"> 
      <td><font size="2" face="tahoma">E-mail</font></td>
      <td><font color="#000000" size="2" face="tahoma">:</font></td>
      <td><input name="email" type="text" id="email" size="30"></td>
    </tr>
    <tr valign="top"> 
      <td><font size="2" face="tahoma">Komentar</font></td>
      <td><font size="2" face="tahoma">:</font></td>
      <td><textarea name='komentar' cols=45 rows=7></textarea></td>
    </tr>
    <tr> 
      <td colspan='2'></td><td align="left"><font color="#FFFFFF" face="tahoma"> 
          <input type='submit' value='Kirim'>
          </font></td>
    </tr>
  </table>
</form>
<style type="text/css">
<!--
a:link {
	color: #000000;
}
a:visited {
	color: #000000;
}
a:hover {
	color: white;
}
a:active {
	color: white;
}
body {
	background-color: #000000;
}
-->
</style>

<table border=0 width=95%>
<td>List Komentar</td>
<?php
if (ISSET($_GET["id_oleh2"])){
$id_oleh2=$_GET["id_oleh2"];
}
$Produk_Dao = new Produk_Dao();
$produk=$Produk_Dao->get($_GET["id_oleh2"]);
$komentar_dao=new Komentar_Dao();
$komentar=$komentar_dao->get_produk($produk->id_oleh2);

$k=1;
foreach ($komentar as $komentar1){

echo"<tr><td align=left><hr>
	<font face=Tahoma size=2><a href='mailto:$komentar1->email'>$komentar1->nama</font><br>
	<font face=Tahoma size=1><b>$komentar1->date</b></font><br><br>
	<font face=Tahoma size=2>$komentar1->komentar</font>
	</td></tr>
";
$k++;
}
echo"<tr><td><hr>";
if (empty($komentar1)){
echo"<br><font face=tahoma size=2><div align=center>Belum Ada Komentar</div></font>";
}
echo"</td></tr></table>";
?>
</div>